#ifndef F_CASSIC_h
#define F_CASSIC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCASSISignal { EDROOMSignalTimeout, EDROOMSignalDestroy, SToListening, SToStandBy, SDataFrame, SSignalFrame, SNextSensorSsiDataFrame };


	friend class CASSI;

	CASSI &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & SsiCtrl;
	CEDROOMInterface & Ssi;
	CEDROOMInterface & StoreAndNextFrame;

	enum edroomStateId{I, Listening, DeliveryServer, Standby};

	enum IdTrans{Init, ToListening, ReceiveData, ReceiveData_CrcFail, ReceiveData_IsData, ReceiveData_IsUnidirectional, ReceiveSignal, ReceiveSignal_IsAck, ReceiveSignal_CrcFail, ReceiveSignal_IsDiscovery, MoreData, NoMoreData, ToStandby,  EDROOMMEMORIA };

	//Constantes



	//Variables

	TEDROOMBool &VBidirectional;
	TEDROOMBool &VCrcOk;
	FrameTypeReceived_t &VFrameType;


	//Pool

	class CEDROOMPOOLCDFrame:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDFrame(TEDROOMUInt32 elemCount,CDFrame *pMem, TEDROOMBool *pMarks);
		CDFrame	* AllocData();
	};
	CEDROOMPOOLCDFrame	& CEDROOMPoolCDFrame;
	class CEDROOMPOOLCDSignal:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDSignal(TEDROOMUInt32 elemCount,CDSignal *pMem, TEDROOMBool *pMarks);
		CDSignal	* AllocData();
	};
	CEDROOMPOOLCDSignal	& EDROOMPoolCDSignal;


	// CONSTRUCTORES

	EDROOMTopContext (CASSI &act, TEDROOMBool & EDROOMpVarVBidirectional, TEDROOMBool & EDROOMpVarVCrcOk, FrameTypeReceived_t & EDROOMpVarVFrameType, CEDROOMPOOLCDFrame & EDROOMpPoolCDFrame, CEDROOMPOOLCDSignal & EDROOMpPoolCDSignal );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	void	FDataConfirmed();

	void	FMoreData();

	void	FNoMoreData();

	void	FReceiveData();

	void	FReceiveSignal();

	void	FRequestNextFrame();

	void	FSendFrameUnidirectional();

	void	FSendToStoreFrame();

	bool_t	GIsAck();

	bool_t	GIsData();

	bool_t	GIsDiscovery();

	bool_t	GIsUnidirectional();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	TEDROOMBool VBidirectional;
	TEDROOMBool VCrcOk;
	FrameTypeReceived_t VFrameType;


	//Pools

	CEDROOMPOOLCDFrame	CEDROOMPoolCDFrame;
	CEDROOMPOOLCDSignal	EDROOMPoolCDSignal;


public:

	// CONSTRUCTOR

	EDROOMTopState (CASSI &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Listening

	// ***********************************************************************



	TEDROOMTransId EDROOMListeningllegada();

	// ***********************************************************************

	// SubEstado Hoja DeliveryServer

	// ***********************************************************************



	TEDROOMTransId EDROOMDeliveryServerllegada();

	// ***********************************************************************

	// SubEstado Hoja Standby

	// ***********************************************************************



	TEDROOMTransId EDROOMStandbyllegada();

};


#endif
